﻿using spriteeditor;
using spriteeditor.Renderer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ttbit.WorkingSpace;

namespace pixeleditor.Editor
{
     class Editor_Text : IWorkResourceEditor
    {
        public string TypeName => Resource_Text.TypeStr;

        TextBox mtext;
        Resource_Text res;
        EditorApp app;
        public void OnActive(EditorApp app, IWorkResource resource)
        {
            this.app = app;
            mtext=new TextBox() { Multiline=true,Width=200,Height=200,ScrollBars= ScrollBars.Both};
            app.EditorAreaFunction.Controls.Add(mtext);
            res = resource as Resource_Text;
            mtext.Text = res.Text;
            mtext.TextChanged += (s, e) =>
            {
                res.Text= mtext.Text; 
            };
        }

        public void OnDeactive(EditorApp app)
        {
            mtext = null;
            res = null;
            app.EditorAreaFunction.Controls.Clear();
        }

        public void OnPointDown(int id, int x, int y)
        {
        }

        public void OnPointMove(int id, int x, int y)
        {
        }

        public void OnPointUp(int id, int x, int y)
        {
        }

        public void OnRender(TTRender2 graphics)
        {
            mtext.Width = app.EditorAreaFunction.Width;
            mtext.Height = app.EditorAreaFunction.Height;
        }
        public void OnPropChange()
        {
            if(res!=null&&mtext!=null)
            {
                mtext.Text = res.Text;
            }
        }
    }
}
